package servlet;

import dao.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import hbase.HbaseUtil;

@WebServlet("/update")
public class UpdateServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        取参数值


//        req.setCharacterEncoding("utf-8");
//        resp.setContentType("text/html;charset=utf-8");

        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String date = req.getParameter("date");
        String number = req.getParameter("number");
        String semester = req.getParameter("semester");
        String status = req.getParameter("status");
        ArrayList<Student> studentArrayList = new ArrayList<>();
        System.out.println("Data Updated Successfully");

        Student student = new Student( );
        student.setId(id);
        student.setName(name);
        student.setDate(date);
        student.setNumber(number);
        student.setSemester(semester);
        student.setStatus(status);
        studentArrayList.add(student);

        HbaseUtil hbaseUpdateUtil = new HbaseUtil();
//         int rel=hbaseUpdateUtil.
//        if(rel>0){
//            pw.print("<script>alert('修改成功！');location.href='BrancheseServlet';</script>");
//        }else{
//            pw.print("<script>alert('修改失败！');location.href='BrancheseServlet';</script>");
//        }

        String obj1 = "";
        try {
            obj1=hbaseUpdateUtil.updateinfo("niit01","2181","id",studentArrayList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw1 =  resp.getWriter();
        pw1.write("<h1>"+  obj1);

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

}
